package com.zoc.web.prd;

import java.math.BigDecimal;
import java.nio.channels.Channels;
import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zoc.common.SuperUtils;
import com.zoc.entity.prd.ChannelInfo;
import com.zoc.entity.prd.LevelMaster;
import com.zoc.entity.prd.Member;
import com.zoc.entity.security.Branch;
import com.zoc.entity.security.Role;
import com.zoc.entity.security.User;
import com.zoc.service.prd.ChannelInfoService;
import com.zoc.service.prd.LevelMasterService;
import com.zoc.web.security.BranchController;

@Controller
@RequestMapping(value = "levelMaster")
public class LevelMasterController {

	@Autowired
	private LevelMasterService levelMasterService;

	private static Logger logger = LoggerFactory.getLogger(LevelMasterController.class);

	@RequestMapping(method = RequestMethod.GET)
	public String main(Model model) {
		logger.debug("Level Info ~");
		return "/prd/levelMaster";
	}

	@RequestMapping(value = "/list", method = { RequestMethod.GET, RequestMethod.POST })
	public @ResponseBody
	List<LevelMaster> list(Model model, LevelMaster entity, @RequestParam(value = "key", required = false) String data) {
		if (!SuperUtils.isNullOrEmpty(data)) {
			entity = SuperUtils.parseObject(data, LevelMaster.class);
		}
		return levelMasterService.list(entity);
	}

	@RequestMapping(value = "/save", method = { RequestMethod.GET, RequestMethod.POST })
	public @ResponseBody
	String save(@RequestParam("data") String data) {
		logger.debug(data);
		List<LevelMaster> entitys = SuperUtils.parseArray(data, LevelMaster.class);
		try{
			levelMasterService.batchSave(entitys);
			return "更新成功";
		}catch(Exception e){
			logger.debug("捕获到了");
			e.printStackTrace();
			return "更新失败";
		}
		
	}
}
